// import 'package:city_pickers/city_pickers.dart';
import 'package:address_picker/address_picker.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:ost_flutter_module/class/entity/store/store_course_detail_entity.dart';
import 'package:ost_flutter_module/class/store/course_page/widgets/store_course_home_card.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';
import 'package:ost_flutter_module/common/dynamic_cell/widgets/dynamic_cell_mutlisttileinfo.dart';
import 'package:ost_flutter_module/common/styles.dart';
import 'package:ost_flutter_module/common/utils.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_list_tile.dart';
import 'package:ost_flutter_module/widget/custom_widget/text_button.dart';
import 'package:ost_flutter_module/widget/custom_widget/vedio_widget.dart';
import 'package:ost_flutter_module/widget/custom_widget/wrap_tag.dart';
import 'package:ost_flutter_module/widget/dialog/show_bottom_sheet.dart';

class StoreCourseDetailPageBody extends StatefulWidget {
  final StoreCourseDetailEntity entity;

  const StoreCourseDetailPageBody({Key key, this.entity}) : super(key: key);
  @override
  _StoreCourseDetailPageBodyState createState() =>
      _StoreCourseDetailPageBodyState();
}

class _StoreCourseDetailPageBodyState extends State<StoreCourseDetailPageBody> {
  List<String> _list = ['授课地点', '课时', '关联商品'];

  String _addressInfo, _temp = '';
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverList(
          delegate: SliverChildListDelegate([
            StoreVedioWidget(),
            Container(
              height: Adapt.px(36),
              color: colorE2F1FF,
              child: GListTile(
                title: Text(
                  '可用优惠：新春限时9折优惠券',
                  style: TextStyle(color: color306293, fontSize: 14),
                ),
                enable: true,
              ),
            ),
            _buildHeader(),
            ListView.builder(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: 1,
              itemBuilder: (BuildContext context, int index) {
                return DynamicCellMulListTileInfo(
                  list: _list,
                  shadow: false,
                  onTap: (data, index) {
                    _onTap(context, data, index);
                  },
                );
              },
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                horizontal: Adapt.px(Utils.padding),
                vertical: Adapt.px(16),
              ),
              child: Image.asset(Utils.getImgPath('detail')),
            ),
          ]),
        ),
      ],
    );
  }

  Widget _buildHeader() => Container(
        padding: EdgeInsets.symmetric(
          horizontal: Adapt.px(20),
          vertical: Adapt.px(10),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Row(
              children: [
                WrapTag(titles: ['特惠', '精选']),
              ],
            ),
            SizedBox(height: Adapt.px(10)),
            Text(
              '一二三四五一二三四五一二三四五一二三四五一二三四五一二三四五',
              style: TextStyles.courseTitleStyle,
              maxLines: 2,
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text('公开课', style: TextStyles.detailTitleStyle),
                Text('有效期至：长期有效', style: TextStyles.detailTitleStyle),
                Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Text('¥500', style: TextStyles.originalPriceTitleStyle),
                    Text('¥200', style: TextStyles.priceTitleStyle),
                  ],
                ),
              ],
            ),
          ],
        ),
      );

  _onTap(BuildContext context, dynamic data, int index) {
    var widget;
    if (index == 0) widget = _buildAddressWidget(context, data);
    if (index == 1) widget = _buildCourseWidget(context, data);
    if (index == 2) widget = _buildShopWidget(context, data);

    gShowBottomSheet(
      context,
      child: widget,
      cancel: () {},
      done: (value) {
        Navigator.pop(context);

        if (index == 0) {
          _addressInfo = _temp;
          Fluttertoast.showToast(msg: _addressInfo);
        } else if (index == 1) {
        } else if (index == 2) {}
      },
    );
  }

  _buildAddressWidget(BuildContext context, dynamic data) => Container(
        height: Adapt.px(220),
        child: AddressPicker(
          style: TextStyles.titleStyle,
          mode: AddressPickerMode.provinceCityAndDistrict,
          onSelectedAddressChanged: (address) {
            var addressInfo = address.currentProvince.province +
                address.currentCity.city +
                address.currentDistrict.area;
            _temp = addressInfo;
            setState(() {});
          },
        ),
      );

  _buildCourseWidget(BuildContext context, dynamic data) => Padding(
        padding: EdgeInsets.symmetric(
            vertical: Adapt.px(24), horizontal: Adapt.px(10)),
        child: ListView.builder(
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemCount: 3,
          itemBuilder: (context, index) {
            return Padding(
              padding: EdgeInsets.only(bottom: Adapt.px(Utils.padding)),
              child: Container(
                height: Adapt.px(36),
                child: GTextButton(
                  padding: 0,
                  normalBackgroundColor: color0D2A51A1,
                  isStadiumBorder: true,
                  child: Padding(
                    padding: EdgeInsets.only(
                        left: Adapt.px(20), right: Adapt.px(20)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('24节', style: TextStyles.titleStyle),
                        Text('￥ 1200.00',
                            style: TextStyles.titleStyle,
                            textAlign: TextAlign.end),
                      ],
                    ),
                  ),
                  onPressed: () {},
                ),
              ),
            );
          },
        ),
      );

  _buildShopWidget(BuildContext context, dynamic data) => Padding(
        padding: EdgeInsets.only(
          top: Adapt.px(24),
          left: Adapt.px(Utils.padding),
          right: Adapt.px(Utils.padding),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('认知逻辑表达课材料包', style: TextStyles.titleStyle),
            SizedBox(height: Adapt.px(Utils.padding)),
            Text(
              '10种DIY材料包，与课程完美配对。一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十。',
              style: TextStyles.detailTitleStyle,
            ),
            SizedBox(height: Adapt.px(20)),
            ListView.builder(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: 15,
              itemBuilder: (context, index) {
                return StoreCourseHomeCard(
                  type: CourseCardType.relate,
                  onTap: (_) {},
                );
              },
            ),
          ],
        ),
      );
}
